<template>
  <div class="recommend">
    <scroll ref="scroll" class="recommend-content" :data="discList">
      <div>
        <div v-if="sliders.length > 0" class="slider-wrapper">
          <!-- 1.0 轮播图 -->
          <slider>
            <div v-for="item in sliders" :key="item.id">
              <a :href="item.linkUrl">
                <img @load="loadImage" :src="item.picUrl" alt="">
              </a>
            </div>
          </slider>
        </div>
        <div class="recommend-list">
          <h1 class="list-title">热门歌单推荐</h1>
          <ul>
            <li v-for="disc in discList" class="item" :key="disc.dissid">
              <div class="icon">
                <img width="60" height="60" :src="disc.imgurl" alt="">
              </div>
              <div class="text">
                <h2 class="name">{{disc.creator.name}}</h2>
                <p class="desc">{{disc.dissname}}</p>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <loading class="loading-container" v-show="!discList.length"></loading>
    </scroll>
  </div>
</template>

<script>
import { testJsonp, getRecommend, getDiscList } from 'api/recommend'

import Slider from 'base/slider/slider'
import Scroll from 'base/scroll/scroll'
import Loading from 'base/loading/loading'

import { RESULT_OK } from 'api/config'

export default {
  components: { Slider, Scroll, Loading },
  data() {
    return {
      sliders: [],
      discList:[]
    }
  },
  created() {
    // this._getTestJsonp()
    this._getRecommend()

    // setTimeout(() => {
    this._getDiscList()
    // }, 2000)
  },
  methods: {
    _getTestJsonp() {
      testJsonp().then(res => {
        // console.log(res)
      })
    },
    _getRecommend() {
      getRecommend().then(res => {
        // console.log(res)
        if (res.data.code === RESULT_OK) {
          // console.log(res.data.data.slider)
          this.sliders = res.data.data.slider
        }
      })
    },
    _getDiscList() {
      getDiscList().then(res => {
        if (res.data.code === RESULT_OK) {
          this.discList = res.data.data.list
        }
      })
    },
    loadImage() {
      if (!this.checkLoaded) {
        this.$refs.scroll.refresh()
        this.checkLoaded = true
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~common/stylus/variable"
  .recommend
    position: fixed
    width: 100%
    top: 88px
    bottom: 0
    .recommend-content
      height 100%
      overflow: hidden
      .recommend-list
        .list-title
          height: 65px;
          line-height: 65px
          text-align: center
          font-size: 14px;
          color: #ffcd32;
      .item
          display flex
          padding 0px 20px 20px
          .icon
            padding-right 20px
          .text
            display flex
            flex-direction column
            font-size $font-size-medium
            justify-content center
            line-height 20px
            .name
              margin-bottom 10px
              color $color-text
            .desc
              color $color-text-d
      .loading-container
        position absolute
        top 50%
        width 100%
        transform translateY(-50%)
</style>


